<template>
	<view>
		<block v-if="isload">
			<form @submit="subform">
				<view class="apply_box">
					<view class="apply_item">
						<view>核销佣金比</view>
						<view class="flex-y-center">{{ info.settlement_rate }}%</view>
					</view>
					<view class="apply_item">
						<view>领酒返点</view>
						<view class="flex-y-center">{{ info.receiving_rebate }}</view>
					</view>
					<view class="apply_item">
						<view>服务费</view>
						<view class="flex-y-center">{{ info.service_charge }}</view>
					</view>
					<view class="apply_item">
						<view>封顶服务费</view>
						<view class="flex-y-center">{{ info.service_charge_max }}</view>
					</view>
					<view class="apply_item">
						<view>商品库存</view>
						<view class="flex-y-center">{{ info.product_stock || 0 }}</view>
					</view>
				</view>
			</form>

		</block>
		<loading v-if="loading"></loading>
		<dp-tabbar :opt="opt"></dp-tabbar>
		<popmsg ref="popmsg"></popmsg>
	</view>
</template>

<script>
var app = getApp();

export default {
	data() {
		return {
			opt: {},
			loading: false,
			isload: false,
			menuindex: -1,

			pre_url: app.globalData.pre_url, static_url: app.globalData.static_url,
			datalist: [],
			pagenum: 1,
			cateArr: [],
			cindex: 0,
			pic: [],
			pics: [],
			info: {},
			latitude: '',
			longitude: '',
			address: '',
			pagecontent: [],
		};
	},

	onLoad: function (opt) {
		this.opt = app.getopts(opt);
		this.getdata();
	},
	onPullDownRefresh: function () {
		this.getdata();
	},
	methods: {
		getdata: function () {
			var that = this;
			that.loading = true;
			app.get('AdminIndex/setinfo', {}, function (res) {
				that.loading = false;
				if (res.status == 2) {
					app.alert(res.msg, function () {
						app.goto('/admin/index/index', 'redirect');
					})
					return;
				}
				uni.setNavigationBarTitle({
					title: res.title
				});
				var clist = res.clist;
				var cateArr = [];
				for (var i in clist) {
					cateArr.push(clist[i].name);
				}
				var pics = res.info ? res.info.pics : '';
				if (pics) {
					pics = pics.split(',');
				} else {
					pics = [];
				}
				that.pics = pics;
				that.info = res.info;
				that.address = res.info.address;
				that.latitude = res.info.latitude;
				that.longitude = res.info.longitude;
				that.pagecontent = res.pagecontent;
				that.cateArr = cateArr;
				that.pic = res.info.logo ? [res.info.logo] : [];
				that.loaded();
			});
		},
		cateChange: function (e) {
			this.cindex = e.detail.value;
		},
		locationSelect: function () {
			var that = this;
			uni.chooseLocation({
				success: function (res) {
					that.info.address = res.name;
					that.info.latitude = res.latitude;
					that.info.longitude = res.longitude;
					that.address = res.name;
					that.latitude = res.latitude;
					that.longitude = res.longitude;
				}
			});
		},

		bindStartHoursChange: function (e) {
			this.start_hours = e.target.value
		},
		bindEndHoursChange: function (e) {
			this.end_hours = e.target.value
		},

		bindStartHours2Change: function (e) {
			this.start_hours2 = e.target.value
		},
		bindEndHours2Change: function (e) {
			this.end_hours2 = e.target.value
		},

		bindStartHours3Change: function (e) {
			this.start_hours3 = e.target.value
		},
		bindEndHours3Change: function (e) {
			this.end_hours3 = e.target.value
		},
		subform: function (e) {
			var that = this;
			var info = e.detail.value;
			if (info.linktel == '') {
				app.error('请填写客服电话');
				return false;
			}
			if (info.zuobiao == '') {
				//app.error('请选择店铺坐标');
				//return false;
			}
			if (info.address == '') {
				app.error('请填写店铺地址');
				return false;
			}
			if (info.pic == '') {
				app.error('请上传商家主图');
				return false;
			}
			if (info.pics == '') {
				app.error('请上传商家照片');
				return false;
			}
			info.address = that.address;
			info.latitude = that.latitude;
			info.longitude = that.longitude;

			app.showLoading('提交中');
			app.post("AdminIndex/setinfo", {
				info: info,
				pagecontent: that.pagecontent,
			}, function (res) {
				app.showLoading(false);
				if (res.status == 1) {
					app.success(res.msg);
					setTimeout(function () {
						app.goto('index');
					}, 1000);
				} else {
					app.error(res.msg);
				}
			});
		},
		isagreeChange: function (e) {
			console.log(e.detail.value);
			var val = e.detail.value;
			if (val.length > 0) {
				this.isagree = true;
			} else {
				this.isagree = false;
			}
		},
		showxieyiFun: function () {
			this.showxieyi = true;
		},
		hidexieyi: function () {
			this.showxieyi = false;
			this.isagree = true;
		},
		uploadimg: function (e) {
			var that = this;
			var field = e.currentTarget.dataset.field
			var pics = that[field]
			if (!pics) pics = [];
			app.chooseImage(function (urls) {
				for (var i = 0; i < urls.length; i++) {
					pics.push(urls[i]);
				}
				if (field == 'pic') that.pic = pics;
				if (field == 'pics') that.pics = pics;
				if (field == 'zhengming') that.zhengming = pics;
			}, 1)
		},
		removeimg: function (e) {
			var that = this;
			var index = e.currentTarget.dataset.index
			var field = e.currentTarget.dataset.field
			if (field == 'pic') {
				var pics = that.pic
				pics.splice(index, 1);
				that.pic = pics;
			} else if (field == 'pics') {
				var pics = that.pics
				pics.splice(index, 1);
				that.pics = pics;
			} else if (field == 'zhengming') {
				var pics = that.zhengming
				pics.splice(index, 1);
				that.zhengming = pics;
			}
		},
		detailAddtxt: function () {
			this.$refs.dialogDetailtxt.open();
		},
		dialogDetailtxtClose: function () {
			this.$refs.dialogDetailtxt.close();
		},
		catcheDetailtxt: function (e) {
			console.log(e)
			this.catche_detailtxt = e.detail.value;
		},
		dialogDetailtxtConfirm: function (e) {
			var detailtxt = this.catche_detailtxt;
			console.log(detailtxt)
			var Mid = 'M' + new Date().getTime() + parseInt(Math.random() * 1000000);
			var pagecontent = this.pagecontent;
			pagecontent.push({
				"id": Mid,
				"temp": "text",
				"params": {
					"content": detailtxt,
					"showcontent": detailtxt,
					"bgcolor": "#ffffff",
					"fontsize": "14",
					"lineheight": "20",
					"letter_spacing": "0",
					"bgpic": "",
					"align": "left",
					"color": "#000",
					"margin_x": "0",
					"margin_y": "0",
					"padding_x": "5",
					"padding_y": "5",
					"quanxian": {
						"all": true
					},
					"platform": {
						"all": true
					}
				},
				"data": "",
				"other": "",
				"content": ""
			});
			this.pagecontent = pagecontent;
			this.$refs.dialogDetailtxt.close();
		},
		detailAddpic: function () {
			var that = this;
			app.chooseImage(function (urls) {
				var Mid = 'M' + new Date().getTime() + parseInt(Math.random() * 1000000);
				var pics = [];
				for (var i in urls) {
					var picid = 'p' + new Date().getTime() + parseInt(Math.random() * 1000000);
					pics.push({
						"id": picid,
						"imgurl": urls[i],
						"hrefurl": "",
						"option": "0"
					})
				}
				var pagecontent = that.pagecontent;
				pagecontent.push({
					"id": Mid,
					"temp": "picture",
					"params": {
						"bgcolor": "#FFFFFF",
						"margin_x": "0",
						"margin_y": "0",
						"padding_x": "0",
						"padding_y": "0",
						"quanxian": {
							"all": true
						},
						"platform": {
							"all": true
						}
					},
					"data": pics,
					"other": "",
					"content": ""
				});
				that.pagecontent = pagecontent;
			}, 9);
		},
		detailAddvideo: function () {
			var that = this;
			uni.chooseVideo({
				sourceType: ['album', 'camera'],
				success: function (res) {
					var tempFilePath = res.tempFilePath;
					app.showLoading('上传中');
					uni.uploadFile({
						url: app.globalData.baseurl + 'ApiImageupload/uploadImg/aid/' + app
							.globalData.aid + '/platform/' + app.globalData.platform +
							'/session_id/' + app.globalData.session_id,
						filePath: tempFilePath,
						name: 'file',
						success: function (res) {
							app.showLoading(false);
							var data = JSON.parse(res.data);
							if (data.status == 1) {
								that.video = data.url;
								var pagecontent = that.pagecontent;
								var Mid = 'M' + new Date().getTime() + parseInt(Math
									.random() * 1000000);
								pagecontent.push({
									"id": Mid,
									"temp": "video",
									"params": {
										"bgcolor": "#FFFFFF",
										"margin_x": "0",
										"margin_y": "0",
										"padding_x": "0",
										"padding_y": "0",
										"src": data.url,
										"quanxian": {
											"all": true
										},
										"platform": {
											"all": true
										}
									},
									"data": "",
									"other": "",
									"content": ""
								});
								that.pagecontent = pagecontent;
							} else {
								app.alert(data.msg);
							}
						},
						fail: function (res) {
							app.showLoading(false);
							app.alert(res.errMsg);
						}
					});
				},
				fail: function (res) {
					console.log(res); //alert(res.errMsg);
				}
			});
		},
		detailMoveup: function (e) {
			var index = e.currentTarget.dataset.index;
			var pagecontent = this.pagecontent;
			if (index > 0)
				pagecontent[index] = pagecontent.splice(index - 1, 1, pagecontent[index])[0];
		},
		detailMovedown: function (e) {
			var index = e.currentTarget.dataset.index;
			var pagecontent = this.pagecontent;
			if (index < pagecontent.length - 1)
				pagecontent[index] = pagecontent.splice(index + 1, 1, pagecontent[index])[0];
		},
		detailMovedel: function (e) {
			var index = e.currentTarget.dataset.index;
			var pagecontent = this.pagecontent;
			pagecontent.splice(index, 1);
		},
	}
}
</script>
<style>
radio {
	transform: scale(0.6);
}

checkbox {
	transform: scale(0.6);
}

.apply_box {
	padding: 2rpx 24rpx 0 24rpx;
	background: #fff;
	margin: 24rpx;
	border-radius: 10rpx
}

.apply_title {
	background: #fff
}

.apply_title .qr_goback {
	width: 18rpx;
	height: 32rpx;
	margin-left: 24rpx;
	margin-top: 34rpx;
}

.apply_title .qr_title {
	font-size: 36rpx;
	color: #242424;
	font-weight: bold;
	margin: 0 auto;
	line-height: 100rpx;
}

.apply_item {
	line-height: 100rpx;
	display: flex;
	justify-content: space-between;
	border-bottom: 1px solid #eee
}

.apply_box .apply_item:last-child {
	border: none
}

.apply_item input {
	width: 100%;
	border: none;
	color: #111;
	font-size: 28rpx;
	text-align: right
}

.apply_item input::placeholder {
	color: #999999
}

.apply_item textarea {
	width: 100%;
	min-height: 200rpx;
	padding: 20rpx 0;
	border: none;
}

.apply_item .upload_pic {
	margin: 50rpx 0;
	background: #F3F3F3;
	width: 90rpx;
	height: 90rpx;
	text-align: center
}

.apply_item .upload_pic image {
	width: 32rpx;
	height: 32rpx;
}

.set-btn {
	width: 90%;
	margin: 0 5%;
	height: 96rpx;
	line-height: 96rpx;
	border-radius: 48rpx;
	color: #FFFFFF;
	font-weight: bold;
}

.layui-imgbox {
	margin-right: 16rpx;
	margin-bottom: 10rpx;
	font-size: 24rpx;
	position: relative;
}

.layui-imgbox-close {
	position: absolute;
	display: block;
	width: 32rpx;
	height: 32rpx;
	right: -16rpx;
	top: -16rpx;
	z-index: 90;
	color: #999;
	font-size: 32rpx;
	background: #fff
}

.layui-imgbox-close image {
	width: 100%;
	height: 100%
}

.layui-imgbox-img {
	display: block;
	width: 200rpx;
	height: 200rpx;
	padding: 2px;
	border: #d3d3d3 1px solid;
	background-color: #f6f6f6;
	overflow: hidden
}

.layui-imgbox-img>image {
	max-width: 100%;
}

.layui-imgbox-repeat {
	position: absolute;
	display: block;
	width: 32rpx;
	height: 32rpx;
	line-height: 28rpx;
	right: 2px;
	bottom: 2px;
	color: #999;
	font-size: 30rpx;
	background: #fff
}

.uploadbtn {
	position: relative;
	height: 200rpx;
	width: 200rpx
}

.form-box {
	padding: 2rpx 24rpx 0 24rpx;
	background: #fff;
	margin: 24rpx;
	border-radius: 10rpx
}

.form-item {
	line-height: 100rpx;
	display: flex;
	justify-content: space-between;
	border-bottom: 1px solid #eee
}

.form-item .f1 {
	color: #222;
	width: 200rpx;
	flex-shrink: 0
}

.form-item .f2 {
	display: flex;
	align-items: center
}

.form-box .form-item:last-child {
	border: none
}

.form-box .flex-col {
	padding-bottom: 20rpx
}

.detailop {
	display: flex;
	line-height: 60rpx
}

.detailop .btn {
	border: 1px solid #ccc;
	margin-right: 10rpx;
	padding: 0 16rpx;
	color: #222;
	border-radius: 10rpx
}

.detaildp {
	position: relative;
	line-height: 50rpx
}

.detaildp .op {
	width: 100%;
	display: flex;
	justify-content: flex-end;
	font-size: 24rpx;
	height: 60rpx;
	line-height: 60rpx;
	margin-top: 10rpx
}

.detaildp .op .btn {
	background: rgba(0, 0, 0, 0.4);
	margin-right: 10rpx;
	padding: 0 10rpx;
	color: #fff
}

.detaildp .detailbox {
	border: 2px dashed #00a0e9
}

.uni-popup-dialog {
	width: 300px;
	border-radius: 5px;
	background-color: #fff;
}

.uni-dialog-title {
	display: flex;
	flex-direction: row;
	justify-content: center;
	padding-top: 15px;
	padding-bottom: 5px;
}

.uni-dialog-title-text {
	font-size: 16px;
	font-weight: 500;
}

.uni-dialog-content {
	display: flex;
	flex-direction: row;
	justify-content: center;
	align-items: center;
	padding: 5px 15px 15px 15px;
}

.uni-dialog-content-text {
	font-size: 14px;
	color: #6e6e6e;
}

.uni-dialog-button-group {
	display: flex;
	flex-direction: row;
	border-top-color: #f5f5f5;
	border-top-style: solid;
	border-top-width: 1px;
}

.uni-dialog-button {
	display: flex;
	flex: 1;
	flex-direction: row;
	justify-content: center;
	align-items: center;
	height: 45px;
}

.uni-border-left {
	border-left-color: #f0f0f0;
	border-left-style: solid;
	border-left-width: 1px;
}

.uni-dialog-button-text {
	font-size: 14px;
}

.uni-button-color {
	color: #007aff;
}
</style>